package com.weizai.carshop.controller;

import com.weizai.carshop.common.result.ResponseResult;
import com.weizai.carshop.model.dto.LoginDto;
import com.weizai.carshop.model.vo.LoginVo;
import com.weizai.carshop.model.vo.UserInfoVo;
import com.weizai.carshop.service.LoginService;
import com.weizai.carshop.service.UploadFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Tag(name = "后台管理系统--登录")
@RestController
@RequestMapping("/api/v1/admin")
public class UserController {
    @Autowired
    private LoginService loginService;

    @Autowired
    private UploadFileService uploadFileService;

    /**
     * 用户登录
     * @param loginDto
     * @return
     */
    @Operation(summary = "登录")
    @PostMapping("/login")
    public ResponseResult<LoginVo> login(@RequestBody LoginDto loginDto){
        LoginVo loginVo = loginService.login(loginDto);
        return ResponseResult.okResult(loginVo);
    }


    /**
     * 获取用户信息
     */
    @Operation(summary = "获取用户信息")
    @PostMapping("/info")
    public ResponseResult<UserInfoVo> info(){
        UserInfoVo userInfoVo = loginService.getUserInfo();
        return ResponseResult.okResult(userInfoVo);
    }

    /**
     * 图片文件上传
     */
    @Operation(summary = "文件上传")
    @PostMapping("/upload")
    public ResponseResult uploadFile(MultipartFile file){
        return uploadFileService.uploadImgFile(file) ;
    }

}
